<!--{include file="header.html"}-->
<!-- END HEAD -->

<!-- BEGIN BODY -->
<body class="page-header-fixed">
<!-- BEGIN HEADER -->
<!--{include file="top.html"}-->
<!-- END HEADER -->

<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
    <!-- BEGIN SIDEBAR -->
    <div class="page-sidebar nav-collapse collapse">
        <!-- BEGIN SIDEBAR MENU -->
        <!--{include file="menu.html"}-->
        <!-- END SIDEBAR MENU -->
    </div>
    <!-- END SIDEBAR --
    <!-- BEGIN PAGE -->
    <div class="page-content">
        <!-- BEGIN PAGE CONTAINER-->
        <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
            <div class="row-fluid">
                <div class="span12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <!--{include file="nav.html"}-->
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="row-fluid">
                <div class="span12">
                    <!-- BEGIN VALIDATION STATES-->
                    <div class="portlet box blue">
                        <div class="portlet-title">
                            <div class="caption"><i class="icon-reorder"></i><!--{$current.last}--></div>
                        </div>
                        <div class="portlet-body form e_coupon">
                            <!--歌曲添加开始-->
                            <div class="goods_add">
                            <form method="post" id="form_ticket_add" name="form_ticket_add" class="form-horizontal">
                                <input type="hidden" name="formhash" value="<!--{$formhash}-->" />
                                <input type="hidden" name="id_ticket" id="id_ticket" value="<!--{$id_ticket}-->"/>
                                <input type="hidden" value="<!--{$url_prefix}--><!--{$url_action}-->" id="jobaction"/>
                                <div class="alert alert-error hide">
                                    <button class="close" data-dismiss="alert"></button>
                                    请确保输入的内容符合提交条件，再点击提交！
                                </div>
                                <div class="alert alert-success hide">
                                    <button class="close" data-dismiss="alert"></button>
                                    你的信息已成功完成验证！
                                </div>
                                <div class="control-group">
                                    <label class="control-label">名称<span class="required">*</span></label>
                                    <div class="controls">
                                        <div id="form_2_membership_error"></div>
                                        <input name="name" type="text" class="span6 m-wrap" value="<!--{$ticket_info.name}-->"/>
                                        <b class="hint">最多不超过20个字</b>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">类型<span class="required">*</span></label>
                                    <div class="controls">
                                        <label class="radio">
                                        <input type="radio" name="type" value="realtime" <!--{if $ticket_info.type}--><!--{if $ticket_info.type == 'realtime'}--> checked='checked'<!--{/if}--><!--{else}--> checked='checked'<!--{/if}-->/>实时创建
                                        </label>
                                        <label class="radio">
                                        <input type="radio" name="type" value="beforehand" disabled="false"/>预先创建
                                        </label>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">最大数量<span class="required">*</span></label>
                                    <div class="controls">
                                        <input name="number" type="text" class="span6 m-wrap" value="<!--{$ticket_info.quantity|default:1}-->" maxlength="6" onKeyUp="validateInt(this);" onBlur="validateInt(this);"/>
                                        <b class="hint">最多不超999999</b>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">验证码长度<span class="required">*</span></label>
                                    <div class="controls">
                                        <input name="length" type="text" class="span6 m-wrap" value="<!--{$ticket_info.length|default:8}-->" maxlength="2" onKeyUp="validateInt(this);" onBlur="validateInt(this);"/>
                                        <b class="hint">请输入8-12的数字</b>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">图片</label>
                                    <div class="controls">
                                        <div id="show_ticket" class="show_synopsis_pic">
                                        <!--{if $ticket_info.image}-->
                                            <div id="attach_url" class="fileupload-new thumbnail">
                                                <img src="<!--{$ticket_info.image|get_img_url:'ticket'}-->"/>
                                                <a onclick="delete_img(this)"></a>
                                            </div>
                                        <!--{/if}-->
                                        </div>
                                        <input type="button" id="uploadTicketBtn" value="上传" class="btn blue post_activity_upload"/>
                                        <input type="hidden" id="fileNum" name="fileNum" value="<!--{if empty($ticket_info.image)}-->0<!--{else}-->1<!--{/if}-->">
                                        <input type="hidden" id="image_src" name="image_src" value=""/>
                                        <b class="hint">图片大小50px X 50px</b>
                                    </div>
                                </div>
                                <div class="control-group clearfix">
                                    <label class="control-label">有效时间<span class="required">*</span></label>
                                    <div class="controls time clearfix">
                                        <ul>
                                            <li><span>开始时间：</span>
                                                <input type="text" value="<!--{substr($ticket_info.valid_begin,0,10)}-->" style="width:172px;" id="valid_begin" name="valid_begin" class="Wdate" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d',errDealMode:1,readOnly:true})"/>
                                                <!--<a href="#">852</a>--></li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="control-group clearfix">
                                    <label class="control-label"></label>
                                    <div class="controls time clearfix">
                                        <ul>
                                            <li><span>结束时间：</span>
                                                <input type="text" value="<!--{substr($ticket_info.valid_end,0,10)}-->" style="width:172px;" id="valid_end" name="valid_end" class="Wdate" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:'%y-%M-%d',errDealMode:1,readOnly:true})"/>
                                                <!--<a href="#">852|default:date('Y-m-d H:i:s',strtotime('+1 day'))</a>--></li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">电子券说明<span class="required">*</span></label>
                                    <div class="controls">
                                        <textarea name="content" id="content" cols="" rows=""><!--{$ticket_info.describe}--></textarea>
                                        <p>请输入长度在10到60000个字符,图片格式:jpeg,jpg,gif,png,单张图片上传文件大小不超过1M</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label">兑换地址</label>
                                    <div class="controls">
                                        <input name="address" type="text" class="span6 m-wrap" value="<!--{$ticket_info.address}-->" maxlength="50"/>
                                    </div>
                                </div>
                            </form>
                                <div class="form-actions">
                                    <button type="submit" class="btn blue" id="ticket_btn">保存</button>
                                </div>
                            </div>
                            <!--歌曲添加结束-->
                        </div>
                    </div>
                    <!-- END VALIDATION STATES-->
                </div>
            </div>
            <!-- END PAGE CONTENT-->
        </div>
        <!-- END PAGE CONTAINER-->
    </div>
    <!-- END PAGE -->
</div>
<!-- END CONTAINER -->

<!-- BEGIN FOOTER -->
<!--{include file="footer.html"}-->
	<!-- END FOOTER -->
<script type="text/javascript" src="<!--{$url_prefix}-->media/js/ajaxupload.js"></script>
<script type="text/javascript" src="<!--{$url_prefix}-->media/js/My97DatePicker/WdatePicker.js"></script>
<script src="<!--{$url_prefix}-->media/kindeditor/kindeditor-min.js"></script>
<script src="<!--{$url_prefix}-->media/kindeditor/lang/zh_CN.js"></script>
<script src="<!--{$url_prefix}-->media/kindeditor/editor.js"></script>
<script src="<!--{$url_prefix}-->media/kindeditor/plugins/code/prettify.js"></script>
	<script>
    jQuery(document).ready(function() {
       App.init();
       FormValidation.ticketInit();

        var url = '<!--{$url_prefix}-->';
        //上传海报图片
        uplodImage('uploadTicketBtn', 'image_src', 'show_ticket',url);

        var editor;
        KindEditor.ready(function(K) {
            editor = K.create('textarea[name="content"]', {
                resizeType : 1,
                themeType:'default',
                allowImageUpload : true,
                uploadJson:url+'files/upload_all_file/ticket_editor',
                shadowMode:false,
                allowMediaUpload:false,
                afterBlur:function(){
                    this.sync();
                    var content = $('#content').val();
                    if(60000 > content.length && content.length > 10){
                        $('#content').parent().children('.help-inline').remove();
                        $('#content').parent().parent().removeClass('error');
                    }
                },
            items : [ 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor',
                'bold', 'italic', 'underline', 'removeformat', '|',
                'justifyleft', 'justifycenter', 'justifyright',
                'insertorderedlist', 'insertunorderedlist' ,'|','table','|','image', 'multiimage','|','link','unlink','emoticons','media']//,'media'
            });
        });
    });


    //2日期比较大小
    function dateCompare(startdate,enddate){
        var arr=startdate.split("-");
        var starttime=new Date(arr[0],arr[1],arr[2]);
        var starttimes=starttime.getTime();

        var arrs=enddate.split("-");
        var lktime=new Date(arrs[0],arrs[1],arrs[2]);
        var lktimes=lktime.getTime();
        if(starttimes>=lktimes)
            return false;
        else
            return true;
    }
    /*
    * 提交电子券信息
    * */
    $("#ticket_btn").click(function(){
        var valid_begin = $('#valid_begin').val();
        var valid_end = $('#valid_end').val();
        if(valid_begin == ''){
            alert("请选择电子券的有效开始时间！");
            return false;
        }else if(valid_end == ''){
            alert("请选择电子券的有效结束时间！");
            return false;
        }else if(!dateCompare(valid_begin,valid_end)){
            alert("请选择的电子券开始时间小于结束时间！");
            return false;
        }
//        验证通过提交表单
        $("#form_ticket_add").submit();
    });

    /**
     * 日期选择
     * @param param
     */
    function SelectDate(param)
    {
        var flag = arguments[1] ? arguments[1] : false;
        var hourNmae = arguments[2] ? arguments[2] : '';
        var YYMMDD = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})/;
        if( ! YYMMDD.test($(param).val()))$(param).val('');
        return WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-%d',errDealMode:1,readOnly:true,onpicked:function(){
        }});
    }

    //删除上传的附件图片
    function delete_img(obj){
        $(obj).parent().remove();
        $('#fileNum').val(0);
        $('#image_src').val('');
    }
	</script>
</body>
<!-- END BODY -->
</html>